package com.elepro.shoppingmall.controller.orders;

import com.elepro.shoppingmall.entity.orders.Order;
import com.elepro.shoppingmall.entity.orders.OrdersInfo;
import com.elepro.shoppingmall.entity.orders.ShoppingCart;
import com.elepro.shoppingmall.service.orders.OrderServiceIm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/orders")
@CrossOrigin
public class OrderController {

    @Autowired
    private OrderServiceIm orderServiceIm;

    /**
     * 查询所有订单
     * @param userId
     * @return
     */
    @GetMapping("/getOrderByUserId")
    public List<Order> getOrderByUserId(@RequestParam("userId") Long userId){
        return orderServiceIm.getOrderByUserId(userId);
    }

    /**
     * 查询1订单的n商品
     * @param orderId
     * @return
     */
    @GetMapping("/getOrderInfoList")
    public List<OrdersInfo> getOrderInfoList(String orderId){
        return orderServiceIm.getOrderInfoList(orderId);
    }

    /**
     * 添加订单
     * @param shoppingCartList
     * @return
     */
    @PostMapping("/insertOrder")
    public String insertOrder(@RequestBody List<ShoppingCart> shoppingCartList){
        return orderServiceIm.insertOrder(shoppingCartList);
    }
}
